package com.study.wechatboot.autoreply.service.impl;

import com.study.wechatboot.autoreply.pojo.recvmsg.RecvMsgJson;
import com.study.wechatboot.autoreply.service.RecvMsgService;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class RecvMsgServiceImpl implements RecvMsgService {

    @Override
    public String processFromType(RecvMsgJson recvMsgJson) {

        int fromType = recvMsgJson.getData().getData().getFromType();
        String fromWxid = recvMsgJson.getData().getData().getFromWxid();
        String wxid = recvMsgJson.getWxid();
        String msg = recvMsgJson.getData().getData().getMsg();
        int msgSource = recvMsgJson.getData().getData().getMsgSource();
        String messageType;
        if (fromType == 1 && Objects.equals(fromWxid, "wxid_emr0ms104p0012") && msgSource == 0) {
            messageType = "这是一条私聊消息,来自老婆:" + msg;
        } else if (fromType == 1 && msgSource == 0) {
            messageType = "这是一条私聊消息,来自 " + fromWxid + ":" + msg;
        } else if (fromType == 1 && msgSource == 1) {
            messageType = "这是一条发出消息,来自 " + wxid + ":" + msg;
        } else if (fromType == 2) {
            messageType = "群聊消息";
        } else {
            messageType = "公众号消息";
        }
        return messageType;
    }
}
